<template>
  <div class="declare">
    <div>
      <div class="tijiao">
        <div>
          <div @click="fanfans">返回</div>
          <!-- <div @click="tijiaoquanxian">审核</div>
          <div @click="bohui">驳回</div> -->
        </div>
        <el-select
          v-model="status"
          placeholder="请选择"
          style="width: 200px"
          @change="statusChange"
        >
          <el-option
            v-for="item in statuss"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </div>

      <div class="table">
        <el-table :data="tableData" stripe style="width: 100%">
          <el-table-column prop="create_time" label="时间"></el-table-column>
          <el-table-column
            prop="award_name"
            label="可申报奖项"
          ></el-table-column>
          <el-table-column prop="user_data.com_name" label="申请人">
            <template slot-scope="scope">
              <div>
                <span
                  @click="tanchu(1, scope.row)"
                  style="color: #409eff; cursor: pointer"
                  >{{ scope.row.user_data.names }}</span
                >
                @<span
                  @click="tanchu(2, scope.row)"
                  style="color: #409eff; cursor: pointer"
                  >{{ scope.row.user_data.cons }}</span
                >
              </div>
              <!-- <div>
                {{ scope.row.user_data.com_name.join("-")[1] }}
              </div> -->
            </template>
          </el-table-column>
          <el-table-column prop="accessory1" label="申请进度">
            <template slot-scope="scope">
              <div v-if="scope.row.status == 1">未录入</div>
              <div v-if="scope.row.status == 2">录入中</div>
              <div v-if="scope.row.status == 3">已完成(管理员审核)</div>
              <!-- <div v-if="scope.row.status == 4">管理员提交(后台审核)</div> -->
              <div v-if="scope.row.status == 4">管理员提交</div>
              <div v-if="scope.row.status == 5">管理驳回</div>
              <div v-if="scope.row.status == 6">后台拒绝(退回)</div>
              <div v-if="scope.row.status == 7">完成</div>
            </template>
          </el-table-column>
          <el-table-column prop label="评选结果">
            <!-- <template slot-scope="scope"> -->
            <template>
              <!-- <div v-if="scope.row.review_num == 0">暂无</div>
              <div v-else>{{ scope.row.review_num }}</div> -->
              <div>暂无</div>
            </template>
          </el-table-column>
          <el-table-column prop="is_shou" label="纸质材料">
            <template slot-scope="scope">
              <div v-if="scope.row.is_shou == 1">已收到</div>
              <div v-if="scope.row.is_shou == 2">未收到</div>
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="备注"></el-table-column>
          <el-table-column
            prop="user_data.branch"
            label="部门"
          ></el-table-column>
          <el-table-column
            prop="user_data.mobile"
            label="电话"
          ></el-table-column>
          <el-table-column
            prop="user_data.email"
            label="邮箱"
          ></el-table-column>
          <el-table-column label="操作" width="280px">
            <template slot-scope="scope">
              <!-- <el-button
                type="primary"
                size="mini"
                icon="el-icon-edit"
                @click="defen(scope.row)"
                v-if="!scope.row.branch"
                >得分</el-button
              > -->

              <el-button type="primary" size="mini" @click="chakan(scope.row)"
                >查看</el-button
              >
              <el-button type="primary" size="mini" @click="daochu(scope.row)"
                >导出</el-button
              >
              <el-button
                class="btn"
                type="primary"
                size="mini"
                icon="el-icon-edit"
                @click="handleputs(scope.row)"
                >备注</el-button
              >
              <el-button type="primary" size="mini" @click="bohui(scope.row)"
                >驳回</el-button
              >
              <el-select
                v-model="scope.row.is_shous"
                placeholder="纸质材料"
                @change="check_lists(scope.row)"
              >
                <el-option label="已收到" value="1"></el-option>
                <el-option label="未收到" value="2"></el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="fenye">
        <el-pagination
          layout="prev, pager, next"
          :page-size="pageSize"
          @current-change="handleCurrentChange"
          :total="total"
        ></el-pagination>
      </div>
    </div>

    <el-dialog
      title="详情"
      :visible.sync="centerDialogVisible"
      width="70%"
      center
    >
      <div v-if="obj_id == 1"></div>
      <div v-else-if="obj_id == 2">
        <innovation1 :objs="objs"></innovation1>
      </div>
      <div v-else-if="obj_id == 3">
        <present1 :objs="objs"></present1>
      </div>
      <div v-else-if="obj_id == 4">
        <Promotion1 :objs="objs"></Promotion1>
      </div>
      <div v-else-if="obj_id == 5">
        <Promotions1 :objs="objs"></Promotions1>
      </div>
      <div v-else-if="obj_id == 6">
        <craftsman1 :objs="objs"></craftsman1>
      </div>
      <div v-else-if="obj_id == 7">
        <achievement1 :objs="objs"></achievement1>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      title="详情"
      :visible.sync="xiangqingVisibles"
      width="30%"
      center
    >
      <div class="beizhus">
        <div>备注</div>
        <el-input type="textarea" v-model="remark"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="xiangqingVisibles = false">取 消</el-button>
        <el-button type="primary" @click="quedings">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog width="70%" title="历年获奖信息" :visible.sync="outerVisible">
      <el-table :data="listlist" style="width: 100%">
        <el-table-column prop="time" label="获奖时间" width="180">
        </el-table-column>
        <el-table-column prop="num" label="获奖数量" width="180">
        </el-table-column>
        <el-table-column prop="type_name" label="获奖类别" width="180">
        </el-table-column>
        <el-table-column prop="obj_name" label="获奖项目" width="180">
        </el-table-column>
        <el-table-column prop="name" label="申报单位" width="180">
        </el-table-column>
        <el-table-column prop="unit_name" label="主要完成单位" width="180">
        </el-table-column>
        <el-table-column prop="user_name" label="主要完成人" width="180">
        </el-table-column>
        <!-- <el-table-column prop="create_time" label="添加时间" width="180">
        </el-table-column>
        <el-table-column prop="edit_time" label="修改时间" width="180">
        </el-table-column> -->
      </el-table>
      <div class="fenye">
        <el-pagination
          layout="prev, pager, next"
          :page-size="pageSize"
          @current-change="handleCurrentChange1"
          :total="total1"
        ></el-pagination></div
    ></el-dialog>
  </div>
</template>

<script>
import innovation1 from "../components/innovation1.vue";
import present1 from "../components/present1.vue";
import Promotion1 from "../components/Promotion1.vue";
import Promotions1 from "../components/Promotions1.vue";
import craftsman1 from "../components/craftsman1.vue";
import achievement1 from "../components/achievement1.vue";
import innovation2 from "../components/innovation2.vue";
import present2 from "../components/present2.vue";
import Promotion2 from "../components/Promotion2.vue";
import Promotions2 from "../components/Promotions2.vue";
import craftsman2 from "../components/craftsman2.vue";
import achievement2 from "../components/achievement2.vue";
export function checkPhoneNumber(rule, value, callback) {
  const reg = /^1[3|4|5|6|7|8|9]\d{9}$/;
  if (!value) {
    return callback(new Error("请填写手机号码！"));
  } else if (!reg.test(value)) {
    return callback(new Error("请填写正确的手机号码！"));
  } else {
    callback();
  }
}
Date.prototype.format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds(), //毫秒
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
      );
  return fmt;
};
import {
  user_edit,
  user_details_list,
  user_child_details,
  submit_audit,
  split_del,
  turn_downs,
  user_split_remark,
  user_split_is_shou,
  file_download,
  searchIndex,
} from "../axios/api";
export default {
  components: {
    innovation1,
    present1,
    Promotion1,
    Promotions1,
    craftsman1,
    achievement1,

    innovation2,
    present2,
    Promotion2,
    Promotions2,
    craftsman2,
    achievement2,
  },
  watch: {
    centerDialogVisible: function (val) {
      if (!val) {
        this.obj_id = null;
      }
    },
  },
  data() {
    return {
      listlist: [],
      xiangqingVisibles: false,
      zong_id: this.$route.query.id,
      Visible: false,
      centerDialogVisible: false,
      tableData: [],
      page: "1",
      total: 0,
      page1: "1",
      total1: 0,
      objs: {},
      obj_id: "",
      pageSize: 0,
      obj: {},
      outerVisible: false,
      centerDialogVisibles: false,
      rules: {
        com_name: [{ required: true, message: "请输入昵称", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        branch: [{ required: true, message: "请输入部门", trigger: "blur" }],
        user_name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        mobile: [
          { required: true, validator: checkPhoneNumber, trigger: "blur" },
        ],
        email: [
          { required: true, message: "请输入邮箱地址", trigger: "blur" },
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        group_id: [
          { required: true, message: "请选择权限组", trigger: "change" },
        ],
      },
      remark: "",
      com_names: "",
      ruleForm: {
        com_name: "",
        password: "",
        user_name: "",
        branch: "",
        mobile: "",
        email: "",
        group_id: "",
      },
      status: "",
      comName: "",
      i: "",
      statuss: [
        {
          name: "未录入",
          id: 1,
        },
        {
          name: "未完成",
          id: 2,
        },
        {
          name: "已完成(管理员审核)",
          id: 3,
        },
        {
          name: "管理员提交(后台审核) ",
          id: 4,
        },
        {
          name: "管理驳回",
          id: 5,
        },
        {
          name: "后台拒绝(退回)",
          id: 6,
        },
        {
          name: "完成",
          id: 7,
        },
      ],
    };
  },
  created() {
    this.user_details_list();
  },

  methods: {
    handleCurrentChange1(e) {
      console.log(e);
      this.page1 = e;
      this.dakai();
    },
    dakai() {
      let data = {
        name:
          this.i == 1
            ? this.comName.user_data.names
            : this.comName.user_data.cons,
        page: this.page1,
        token: sessionStorage.getItem("Token1"),
      };
      searchIndex(data).then((res) => {
        console.log(res.data);
        this.listlist = res.data.data.data;
        this.total1 = res.data.data.total;
      });
    },
    tanchu(i, e) {
      console.log(e);
      this.i = i;
      this.comName = e;
      this.outerVisible = true;
      this.page1 = 1;
      this.dakai();
    },
    daochu(e) {
      console.log(e);
      // return
      let p = {
        user_split_id: e.id,
      };
      file_download(p).then((res) => {
        let blob = new Blob([res.data], { type: "application/zip" });
        let url = window.URL.createObjectURL(blob);
        const link = document.createElement("a"); // 创建a标签
        link.setAttribute("download", e.award_name);
        link.href = url;
        link.click();
        URL.revokeObjectURL(url); // 释放
      });
    },
    fanfans() {
      this.$router.push({ path: "/shenqing" });
    },
    statusChange() {
      this.user_details_list();
    },
    bohui(e) {
      let params = {
        token: sessionStorage.getItem("Token1"),
        id: e.id,
      };
      turn_downs(params).then((res) => {
        if (res.data.code == 200) {
          this.$message({
            message: "驳回成功",
            type: "success",
          });
          this.user_details_list();
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    tijiaoquanxian() {
      let params = {
        token: sessionStorage.getItem("Token1"),
        com_id: this.zong_id,
      };
      submit_audit(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            message: "提交成功",
            type: "success",
          });
          this.user_details_list();
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    chakan(e) {
      console.log(e);
      let params = {
        id: e.id,
        token: sessionStorage.getItem("Token1"),
      };
      user_child_details(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.obj_id = res.data.data.award_id;
          this.objs = res.data.data;

          this.objs.accomplish_people = this.objs.accomplish_people
            ? JSON.parse(this.objs.accomplish_people)
            : [];
          if (this.objs.domain) {
            this.objs.domain = this.objs.domain;
          }
          this.objs.accomplish = this.objs.accomplish
            ? JSON.parse(this.objs.accomplish)
            : [];
          // if (this.objs.accomplish) {
          //   this.objs.accomplish = JSON.parse(this.objs.accomplish);
          // }

          console.log(this.objs);
          this.centerDialogVisible = true;
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    defen(e) {
      console.log(e);
      let params = {
        id: e.id,
        token: sessionStorage.getItem("Token1"),
      };
      user_child_details(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.obj_id = res.data.data.award_id;
          this.objs = res.data.data;
          this.objs.accomplish_people = JSON.parse(this.objs.accomplish_people);
          if (this.objs.domain) {
            this.objs.domain = JSON.parse(this.objs.domain);
          }
          if (this.objs.accomplish) {
            this.objs.accomplish = JSON.parse(this.objs.accomplish);
          }
          sessionStorage.setItem("obj", JSON.stringify(this.objs));

          this.centerDialogVisibles = true;
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },

    handleputs(e) {
      this.obj = e;
      this.remark = "";
      this.xiangqingVisibles = true;
    },
    user_details_list() {
      let params = {
        token: sessionStorage.getItem("Token1"),
        com_id: this.zong_id,
        page: this.page,
        status: this.status,
      };
      user_details_list(params).then((res) => {
        this.total = parseInt(res.data.data.totalPage);
        this.pageSize = parseInt(res.data.data.pageSize);
        this.tableData = res.data.data.data;
        this.tableData.forEach((item) => {
          var myDate = new Date(item.create_time * 1000);
          myDate.setDate(myDate.getDate());
          item.user_data.names = item.user_data.com_name.split("@")[0];
          item.user_data.cons = item.user_data.com_name.split("@")[1];
          item.create_time = myDate.format("yyyy年MM月dd日");
        });
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm);
          this.ruleForm.token = sessionStorage.getItem("Token");
          user_edit(this.ruleForm).then((res) => {
            console.log(res);
            if (res.data.code == 200) {
              this.$message({
                message: "添加成功",
                type: "success",
              });
              this.resetForm("ruleForm");
              this.centerDialogVisible = false;
            } else {
              this.$message.error(res.data.msg);
            }
            this;
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    check_lists(e) {
      console.log(e);
      let params = {
        token: sessionStorage.getItem("Token1"),
        id: e.id,
        is_shou: e.is_shous,
      };
      user_split_is_shou(params).then((res) => {
        if ((res.data.code = 200)) {
          this.$message({
            message: "变更成功",
            type: "success",
          });
          this.user_details_list();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    quedings() {
      let params = {
        id: this.obj.id,
        token: sessionStorage.getItem("Token1"),
        remark: this.remark,
      };
      user_split_remark(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            message: "备注成功",
            type: "success",
          });
          this.xiangqingVisibles = false;
          this.user_details_list();
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.centerDialogVisible = false;
    },
    handle_put(e) {
      console.log(e);
      this.ruleForm.com_name = e.com_name;
      // this.ruleForm.user_name = e.user_name;
      // this.ruleForm.password = e.password;
      this.ruleForm.branch = e.branch;
      this.ruleForm.mobile = e.mobile;
      this.ruleForm.group_id = e.group_id;
      this.ruleForm.email = e.email;
      this.ruleForm.id = e.id;
      this.centerDialogVisible = true;
    },

    tiaozhuan() {
      // this.$router.push({ path: "/index" });
    },

    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page = val + "";
      this.user_details_list();
    },
    handleput(e) {
      console.log(e);
      this.ruleForm.com_name = e.com_name;
      this.ruleForm.user_name = e.user_name;
      this.ruleForm.password = e.password;
      this.ruleForm.branch = e.branch;
      this.ruleForm.mobile = e.mobile;
      this.ruleForm.group_id = e.group_id;
      this.ruleForm.email = e.email;
      this.Visible = true;
    },
    handleDel(e) {
      console.log(e);
    },
  },
};
</script>

<style scoped>
.declare {
  width: 100%;
  height: 100%;
  background-color: #fff;
  box-sizing: border-box;
  padding: 20px;
  overflow-y: scroll;
}
.table {
  width: 95%;
  height: 80%;
  margin: 0 auto;
}
.xiangqing {
  width: 100%;
  box-sizing: border-box;
}
.xiangqing > div {
  width: 90%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px auto;
}
.fenye {
  width: 100%;
  display: flex;
  justify-content: center;
}
.tijiao {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100px;
  box-sizing: border-box;
}
.tijiao > div {
  display: flex;
}
.tijiao > div > div {
  width: 120px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #409eff;
  color: #fff;
  border-radius: 10px;
  margin-right: 20px;
}
.beizhus {
  display: flex;
  align-items: center;
}
.beizhus > div:nth-child(1) {
  flex: 0 0 80px;
}
</style>
